#ifndef CVCAMERATHREAD_H
#define CVCAMERATHREAD_H

//#include <QThread>
#include <QPixmap>
#include <QtCore/QTimer>
#include "AIThread.h"
#include "cvmat.h"

#include "opencv2/opencv.hpp"
using namespace cv;

class QString;

class CvCameraInner : public QObject
{
    Q_OBJECT

public:
    CvCameraInner(QObject *parent = 0);
    ~CvCameraInner();

    static QImage toQImage(const Mat & image);
    //static bool toQImage(QImage &image, const Mat & matImage);

    QImage &getImage() { return m_image; }

signals:
    void onNewPixmap(QPixmap pixmap);
    //void onNewMat(cv::Mat matImage);

public slots:
    void processFrame();
    void onSuspend();
    void onResume(int mSec = 0);
    bool captureFromFile( QString filename );
    bool captureFromCamera( int nCam );
    QString getFilename() const { return m_strFilename; }
    int getCamNumber() const { return m_nCam; }

private:
    bool initCapture(const QString & strScriptName = "camera");

protected:
    VideoCapture m_VideoCapture;

    QImage m_image; // Background drawing
    QTimer m_timer;
	Mat m_matImage; // The captured image will be only allocated once: in the first video capture
	CvMatrix  m_cvMat;

    QString m_strFilename;
    int m_nCam;
};


#endif // CVCAMERATHREAD_H
